﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;

namespace Projekt_GUI.Forms
{
    public partial class LocationsUebersicht : Form
    {
        OracleHelper oracle { get { return OracleHelper.Instance; } }

        public LocationsUebersicht()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.Manual;
            Point openUpHere = new Point(857,155);
            this.Location = openUpHere;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void LocationsÜbersicht_Load(object sender, EventArgs e)
        {
            Refresh();
        }

        private void Refresh()
        {
            oracle.Open();

            int counter = 0;
            listView1.Items.Clear();

            OracleDataReader r = oracle.Select("Name, Ort, Land, Personen, Nummer", "Locations");
            while (r.Read())
            {
                listView1.Items.Add(r.GetValue(0).ToString());
                listView1.Items[counter].SubItems.Add(r.GetValue(1).ToString());
                listView1.Items[counter].SubItems.Add(r.GetValue(2).ToString());
                listView1.Items[counter].SubItems.Add(r.GetValue(3).ToString());
                listView1.Items[counter].SubItems.Add(r.GetValue(4).ToString());
                counter++;
            }

            oracle.Close();

        }
        private void löschenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Locations loc = new Locations();
            loc.ShowDialog();
            Refresh();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                oracle.Open();
                oracle.Delete("Locations", "Nummer=" + listView1.SelectedItems[0].SubItems[4].Text); oracle.Close();

                Refresh();
            }
        }
    }
}
